Telegram Group & Telegram Channel
🖥 Необходимо определить делегат и реализовать метод

Итак, вот задание:
определить делегат bool CounterHashSetDelegate(int a) и реализовать метод int Function12(HashSet<int> intSet, CounterHashSetDelegate filter), который возвращает количество элементов из intSet, которые удовлетворяют условию filter.
public static  class 
{
public delegate bool CounterHashSetDelegate(int a);
public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if(filter(i))
count++;
}
return count;
}
}



Давайте сразу к сути, решение может выглядеть так:
public delegate bool CounterHashSetDelegate(int a);

class Program
{
static void Main(string[] args)
{
CounterHashSetDelegate d = IsEvenNum;

Console.WriteLine($"Количество четных элементов:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

d = IsGreaterThen;

Console.WriteLine($"Количество элементов > 2:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

Console.ReadKey();
}

public static bool IsEvenNum(int a)
{
return a % 2 == 0;// четное ли число например
}

public static bool IsGreaterThen(int a)
{
return a > 2;//больше ли например
}


public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if (filter(i))
{
count++;
}
}
return count;
}

}

Вот и все дела

@csharp_ci
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/csharp_1001_notes/439
Create:
Last Update:

🖥 Необходимо определить делегат и реализовать метод

Итак, вот задание:
определить делегат bool CounterHashSetDelegate(int a) и реализовать метод int Function12(HashSet<int> intSet, CounterHashSetDelegate filter), который возвращает количество элементов из intSet, которые удовлетворяют условию filter.

public static  class 
{
public delegate bool CounterHashSetDelegate(int a);
public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if(filter(i))
count++;
}
return count;
}
}



Давайте сразу к сути, решение может выглядеть так:
public delegate bool CounterHashSetDelegate(int a);

class Program
{
static void Main(string[] args)
{
CounterHashSetDelegate d = IsEvenNum;

Console.WriteLine($"Количество четных элементов:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

d = IsGreaterThen;

Console.WriteLine($"Количество элементов > 2:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

Console.ReadKey();
}

public static bool IsEvenNum(int a)
{
return a % 2 == 0;// четное ли число например
}

public static bool IsGreaterThen(int a)
{
return a > 2;//больше ли например
}


public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if (filter(i))
{
count++;
}
}
return count;
}

}

Вот и все дела

@csharp_ci

BY C# 1001 notes




Share with your friend now:
tg-me.com/csharp_1001_notes/439

View MORE
Open in Telegram


C 1001 notes Telegram | DID YOU KNOW?

Date: |

What is Telegram Possible Future Strategies?

Cryptoassets enthusiasts use this application for their trade activities, and they may make donations for this cause.If somehow Telegram do run out of money to sustain themselves they will probably introduce some features that will not hinder the rudimentary principle of Telegram but provide users with enhanced and enriched experience. This could be similar to features where characters can be customized in a game which directly do not affect the in-game strategies but add to the experience.

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

C 1001 notes from us


Telegram C# 1001 notes
FROM USA